package com.example.iotmanagerment26.controller;

import com.example.iotmanagerment26.domain.JsonData;
import com.example.iotmanagerment26.service.MoneyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 作者：太难猫
 * 创建时间： 2025/6/17 10:37
 */

@CrossOrigin
@RestController
@RequestMapping("/v1/money")
@Tag(name="结算管理",description = "结算管理的接口")
public class MoneyController {

    @Autowired
    MoneyService moneyService;

    @PostMapping("/pay")
    @Operation(summary = "结算")
    public JsonData pay() {
        int result = moneyService.pay();
        if (result==1) {
            return new JsonData(1,result,"结算成功！");
        }else {
            return new JsonData(0,result,"结算失败! 没有待结算的订单！");
        }
    }

    @PostMapping("/submit")
    @Operation(summary = "提交订单")
    public JsonData submit(String room,int money) {
        int result = moneyService.submit(room,money);
        if (result==1) {
            return new JsonData(1,result,"提交成功");
        }else {
            return new JsonData(0,result,"提交失败,当前还有订单未结算！");
        }
    }

    @PostMapping("/induction")
    @Operation(summary = "感应NFC")
    public JsonData induction() {
        int result = moneyService.induction();
        if (result==1) {
            return new JsonData(1,result,"感应成功！");
        }else {
            return new JsonData(0,result,"感应失败! ");
        }
    }

    @GetMapping("/getinduction")
    @Operation(summary = "获取是否感应到")
    public JsonData getinduction() {
        Map<String, Object> induction = moneyService.getInduction();
        return new JsonData(1,induction,"获取成功！");
    }
}
